{% extends 'base.html' %}
{% block content %}
<div class="card mx-auto" style="max-width:500px;">
    <div class="card-body">
        <h1 class="card-title">{% if form.instance.pk %}编辑图书{% else %}添加图书{% endif %}</h1>
        <form method="post" enctype="multipart/form-data">
            {% csrf_token %}
            {{ form.as_p }}
            {% if form.instance.cover %}
                <div class="mb-3">
                    <img src="{{ form.instance.cover.url }}" alt="封面" style="max-width:120px;max-height:160px;">
                </div>
            {% endif %}
            <button type="submit" class="btn btn-success">保存</button>
            <a href="{% url 'book-list' %}" class="btn btn-secondary">返回列表</a>
        </form>
    </div>
</div>
{% endblock %} 